//  program:	Create replication file for partisan committees
//  task:       *create replication file for most tables and models in submitted version of paper
				*some other tables are created using r files, see related files. Replication of permutation occurs in separatea stata file.
				*data developed in r
//				project: Committee Partisanship
// 				Related files: 08permutation_sim_060319 actually simulates the dataset. this just creates the graphs in the paper

//  author:     Josh Ryan \ November 29, 2019

// #Start
// program setup

set more off




*Additional tables and figures replicated using R file: 07tablesfigsrep_vx_date



use "clogit_final_v3_030720.dta", clear


*scale partydiff
replace partydiff=partydiff/100
replace lagpartydiff=lagpartydiff/100

replace partydiff_wo=partydiff_wo/100
replace lagpartydiff_wo=lagpartydiff_wo/100



*Table: Fixed Effects Logit Estimates of Committee Assignment

*with kernell district ideology
*for reference to compare to fixed effects logit
clogit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.cong, group(icpsr)
*number of distinct obs used in analysis
egen icpsr_comm_cong = concat(icpsr stewartcommid cong) if commassignid==1
qui tab icpsr_comm_cong if e(sample)
di r(r)

*with pres. district partisanship
clogit commassignid c.dispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong, group(icpsr)
qui tab icpsr_comm_cong if e(sample)
di r(r)


*both district partisanship measures--actual models in the papers
eststo c1: logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong, cluster(stewartcommid)
*egen icpsr_comm_cong = concat(icpsr stewartcommid cong) if commassignid==1
qui tab icpsr_comm_cong if e(sample)
di r(r)


eststo c2: logit commassignid c.lndispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong, cluster(stewartcommid)
qui tab icpsr_comm_cong if e(sample)
di r(r)

estout c1 c2, style(tex) cells(b(star fmt(2)) se(par)) starlevels($^\#$ .1 * 0.05) stats(aic N r2) varlabels( ///
lnkernelldispart	"Logged Kernell District Ideology" lagpartydiff_wo "Lagged Avg. Diff. in Committee Partisan Voting"  lndispart "Logged Presidential Vote District Ideology"  ///
rankwithinparty "Committee Party Seniority Rank" commseniority "Committee Overall Seniority" ///
permaj "Maj. Party Percent of Committee Seats")



*Figure: Predicted Probabilities of Committee Choice Conditional on Kernell District Ideology and Average Difference in Partisan Voting

*marginal effects, pred probs
logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong, cluster (stewartcommid)
eststo cp1: margins, at(lnkernelldispart=(-6.907755) lagpartydiff_wo=(0(.25)1)) post vsquish 


logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong, cluster(stewartcommid)
eststo cp2: margins, at(lnkernelldispart=(1.233143) lagpartydiff_wo=(0(.25)1)) post vsquish 


*margins are here:
use "marginaleffects_conditionallogit_kernell_011420_v6.dta", clear
gen interactmerge=99

merge m:m interactmerge using "datwcommpart_v5_030720.dta" 
gen id=_n

*(rarea lci uci partydiffpred if kernelldispred=="min", color(gs15))
graph twoway (hist lagpartydiff_wo, width(1) percent color(gs14) yaxis(2)) ///
(connected margin partydiffpred if kernelldispred=="min" , sort lcolor(black) lpattern(solid) lwidth(thin) msymbol(none) yaxis(1)) ///
(connected lci partydiffpred if kernelldispred=="min"  , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none) yaxis(1)) ///
(connected uci partydiffpred if kernelldispred=="min" , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none) yaxis(1)) ///
(connected margin partydiffpred if kernelldispred=="max" & id<11, sort lcolor(black) lpattern(solid) lwidth(thick) msymbol(none) yaxis(1)) ///
(connected lci partydiffpred if kernelldispred=="max"  & id<11, sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none) yaxis(1)) ///
(connected uci partydiffpred if kernelldispred=="max" & id<11 , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none) yaxis(1)), ///
ytitle("Predicted Pr(Committee Membership)", axis(1)) ytitle("Density of Committee Partisanship", axis(2)) xtitle("Committee Partisanship") ///
 ylabel(0(1)6, axis (2) valuelabel) ylabel(0(.1).3, axis (1) valuelabel) yscale(alt) yscale(alt axis(2)) ///
xlabel(0(10)100, valuelabel) legend(col(1) order(2 "Pred. Prob. at Min. District Ideo. Extremity" 5 "Pred. Prob. at Max. District Ideo. Extremity" 3 "95% Confidence Interval" ) ///
bplacement(nw) ring(1) size(small)) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) title("")



*Table: The Conditional Effect of Distributive Committees on District Partisanship and Partisan Committee Membership
use "clogit_final_v3_030720.dta", clear

*scale partydiff
replace partydiff=partydiff/100
replace lagpartydiff=lagpartydiff/100

replace partydiff_wo=partydiff_wo/100
replace lagpartydiff_wo=lagpartydiff_wo/100


gen appropcomm=0
replace appropcomm=1 if fkconstit==1 
replace appropcomm=1 if stewartcommid==104


eststo dist_m1: logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong if appropcomm==0, cluster(stewartcommid)
eststo dist1: margins, at(lnkernelldispart=(-6.907755) lagpartydiff_wo=(0(.25)1)) post vsquish 
egen icpsr_comm_cong = concat(icpsr stewartcommid cong) if commassignid==1
qui tab icpsr_comm_cong if e(sample)
di r(r)

eststo dist_m2: logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong if appropcomm==1, cluster(stewartcommid)
eststo dist2: margins, at(lnkernelldispart=(-6.907755) lagpartydiff_wo=(0(.25)1)) post vsquish 
qui tab icpsr_comm_cong if e(sample)
di r(r)

eststo dist_m3: logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong if appropcomm==0, cluster(stewartcommid)
eststo dist3: margins, at(lnkernelldispart=(1.233143) lagpartydiff_wo=(0(.25)1)) post vsquish 

eststo dist_m4: logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong if appropcomm==1, cluster(stewartcommid)
eststo dist4: margins, at(lnkernelldispart=(1.233143) lagpartydiff_wo=(0(.25)1)) post vsquish 

estout dist_m1 dist_m2, style(tex) cells(b(star fmt(2)) se(par)) starlevels($^\#$ .1 * 0.05) stats(aic N r2) varlabels( ///
lnkernelldispart	"Logged Kernell District Ideology" lagpartydiff_wo "Lagged Avg. Diff. in Committee Partisan Voting"  lndispart "Logged Presidential Vote District Ideology"  ///
rankwithinparty "Committee Party Seniority Rank" commseniority "Committee Overall Seniority" ///
permaj "Maj. Party Percent of Committee Seats")


*Figure: Predicted Probabilities of Committee Choice for Distributive and Non-Distributive Committees, 
*Conditional on Kernell District Ideology and Average Difference in Committee Partisan Voting

*margins are here:
use "marginaleffects_conditionallogit_kernell_appropcomm_011420_v2.dta", clear

graph twoway (connected margin partydiffpred if kernelldispred=="min" & appropcomm==0, sort lcolor(gray) lpattern(solid) lwidth(thin) msymbol(none) yaxis(1)) ///
(connected lci partydiffpred if kernelldispred=="min" & appropcomm==0 , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected uci partydiffpred if kernelldispred=="min" & appropcomm==0, sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected margin partydiffpred if kernelldispred=="min" & appropcomm==1, sort lcolor(black) lpattern(solid) lwidth(thick) msymbol(none) yaxis(1)) ///
(connected lci partydiffpred if kernelldispred=="min"  & appropcomm==1, sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected uci partydiffpred if kernelldispred=="min" && appropcomm==1 , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)), ///
ytitle("Predicted Pr(Committee Membership)", axis(1)) xtitle("Committee Partisanship") ///
 ylabel(0(.04).28, axis (1) valuelabel) ///
xlabel(0(10)100, valuelabel) legend(col(1) order(1 "Pred. Prob. for Non-Distributive Comms." 4 "Pred. Prob. for Distributive Comms." 3 "95% Confidence Interval" ) ///
bplacement(nw) ring(1) size(small)) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) title("Minimum District" "Ideological Extremity")
graph save conditionaldistcomms_min.gph, replace


graph twoway (connected margin partydiffpred if kernelldispred=="max" & appropcomm==0, sort lcolor(black) lpattern(solid) lwidth(thin) msymbol(none) yaxis(1)) ///
(connected lci partydiffpred if kernelldispred=="max" & appropcomm==0 , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected uci partydiffpred if kernelldispred=="max" & appropcomm==0 , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected margin partydiffpred if kernelldispred=="max" & appropcomm==1, sort lcolor(black) lpattern(solid) lwidth(thick) msymbol(none) yaxis(1)) ///
(connected lci partydiffpred if kernelldispred=="max"  & appropcomm==1 , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected uci partydiffpred if kernelldispred=="max" && appropcomm==1  , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)), ///
ytitle("Predicted Pr(Committee Membership)", axis(1)) xtitle("Committee Partisanship") ///
ylabel(0(.04).14, axis (1) valuelabel)  ///
xlabel(0(10)100, valuelabel) legend(col(1) order(1 "Pred. Prob. for Non-Distributive Comms." 4 "Pred. Prob. for Distributive Comms." 3 "95% Confidence Interval" ) ///
bplacement(nw) ring(1) size(small)) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) title("Maximum District" "Ideological Extremity")
graph save conditionaldistcomms_max.gph, replace

graph combine conditionaldistcomms_min.gph conditionaldistcomms_max.gph, scheme(s1mono) graphregion(fcolor(white) ifcolor(white))


*Table: The Conditional Effect of Outlying District Preferences on Committee Departure

use "datwcommpart_v5_030720.dta", clear

eststo int1: logit memberleft c.abszk##c.votepct rankwithinparty female membermajparty memberparty commleader i.stewartcommid i.cong numterms, cluster(stewartcommid)
margins, at(abszk=(0) votepct=(40(10)100)) post vsquish

logit memberleft c.abszk##c.votepct rankwithinparty female membermajparty memberparty commleader i.stewartcommid i.cong numterms, cluster(stewartcommid)
margins, at(abszk=(4.6) votepct=(40(10)100)) post vsquish


eststo int2: logit memberleft c.abszk##c.kernelldispart rankwithinparty female membermajparty memberparty commleader i.stewartcommid i.cong numterms, cluster(stewartcommid)
margins, at(abszk=(0) kernelldispart=(0(1)3.4)) level(90)

logit memberleft c.abszk##c.kernelldispart rankwithinparty female membermajparty memberparty commleader i.stewartcommid i.cong numterms, cluster(stewartcommid)
margins, at(abszk=(2) kernelldispart=(0(1)3.4)) level(90)


eststo int3: logit memberleft c.abszk##c.dispart rankwithinparty female membermajparty memberparty commleader i.stewartcommid i.cong numterms, cluster(stewartcommid)
eststo pp1: margins, at(abszk=(0) dispart=(0(10)50)) post vsquish

logit memberleft c.abszk##c.dispart rankwithinparty female membermajparty memberparty commleader i.stewartcommid i.cong numterms, cluster(stewartcommid)
eststo pp2: margins, at(abszk=(4.6) dispart=(0(10)50)) post vsquish

estout int1 int2 int3, style(tex) cells(b(star fmt(2)) se(par)) starlevels($^\#$ .1 * 0.05) stats(aic N r2_p) varlabels( ///
abszk "Member Outlierness (Kernell)" votepct "Member Vote Percentage" kernelldispart "Kernell District Partisanship" dispart "Presidential Vote District Partisanship" ///
rankwithinparty "Committee Party Seniority Rank" female "Gender (Female=1)" membermajparty "Majority Party Member (Yes=1)" ///
memberparty "Member Party (Dem.=1)" commleader "Chair or Ranking Member of Any Committee" numterms "Number of Terms Served")


*Figure: Predicted Probabilities of Leaving a Committee Conditional on Outlying District Preferences and District Partisanship

*margins are here:
use "marginaleffects_zdispart_051719_v2.dta", clear
gen interactmerge=99

*gen var to merge on so i can get the rest of the data in with the marginal effects to generate histogram
*but i want to limit the marginal effects to only the first13 observations so create id that i can use to subset (actually doesn't matter for drawing purposes but I think
*it looks cleaner
merge m:m interactmerge using "datwcommpart_v5_030720.dta" 
gen id=_n

graph twoway (hist dispart if numterms<4, width(1) percent color(gs14) yaxis(2)) ///
(connected margin estdis if estabszk==0, sort lcolor(gray) lpattern(solid) lwidth(thin) msymbol(none) yaxis(1)) ///
(connected lci estdis if estabszk==0, sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected uci estdis if estabszk==0, sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected margin estdis if estabszk==4& id<13, sort lcolor(black) lpattern(solid) lwidth(thick) msymbol(none) yaxis(1)) ///
(connected lci estdis if estabszk==4 & id<13, sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected uci estdis if estabszk==4& id<13 , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)), ///
ytitle("Predicted Pr(Committee Departure)", axis(1)) ytitle("Density of Dist. Partisanship", axis(2)) xtitle("Pres. Vote District Extremity") ///
 ylabel(0(.1)1, axis (1) valuelabel) ylabel(0(2)10, axis (2) valuelabel) yscale(alt) yscale(alt axis(2)) ///
xlabel(0(5)50, valuelabel) legend(col(1) order(2 "Pred. Prob. Min. Outlier" 5 "Pred. Prob. Max. Outlier" 3 "95% Confidence Interval" ) ///
bplacement(nw) ring(1) size(small)) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) title("")
graph save outlierinteract.gph, replace












*Table: The Conditional Effect of Outlying District Preferences and Distributive Committee on Committee Departure

use "datwcommpart_v5_030720.dta", clear

gen appropcomm=0
replace appropcomm=1 if fkconstit==1 
replace appropcomm=1 if stewartcommid==104

eststo absapprop1: logit memberleft c.abszk##c.votepct##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj numterms i.cong numterms, cluster(stewartcommid)
margins, at(abszk=(0) votepct=(40(10)100)) post vsquish

logit memberleft c.abszk##c.votepct##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
margins, at(abszk=(4.6) votepct=(40(10)100)) post vsquish


eststo absapprop2: logit memberleft c.abszk##c.kernelldispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
margins, at(appropcomm=(0) abszk=(0) kernelldispart=(0(1)3.4)) level(90)

logit memberleft c.abszk##c.kernelldispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
margins, at(appropcomm=(1) abszk=(0) kernelldispart=(0(1)3.4)) level(90)


eststo absapprop3: logit memberleft c.abszk##c.dispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
eststo pp1: margins, at(abszk=(0) dispart=(0(10)50)) post vsquish

logit memberleft c.abszk##c.dispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
eststo pp2: margins, at(abszk=(4.6) dispart=(0(10)50)) post vsquish

estout absapprop1 absapprop2 absapprop3, style(tex) cells(b(star fmt(2)) se(par)) starlevels($^\#$ .1 * 0.05) stats(aic N r2_p) varlabels( ///
abszk "Member Outlierness (Kernell)" votepct "Member Vote Percentage" kernelldispart "Kernell District Partisanship" dispart "Presidential Vote District Partisanship" ///
rankwithinparty "Committee Party Seniority Rank" female "Gender (Female=1)" membermajparty "Majority Party Member (Yes=1)" ///
memberparty "Member Party (Dem.=1)" commleader "Chair or Ranking Member of Any Committee" numterms "Number of Terms Served" grosewart "Grosewart Committee Value" permaj "Maj. Party Percent of Committee Seats")

*Figure: Predicted Probabilities of Committee Departures Conditional on Outlying Preferences, Distributive Committee, and District Partisanship

eststo absapprop3: logit memberleft c.abszk##c.dispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
eststo pp1: margins, at(appropcomm=(0) abszk=(0) dispart=(0(10)50)) post vsquish level(90)

logit memberleft c.abszk##c.dispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
eststo pp2: margins, at(appropcomm=(1) abszk=(0) dispart=(0(10)50)) post vsquish level(90)

eststo absapprop3: logit memberleft c.abszk##c.dispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
eststo pp3: margins, at(appropcomm=(0) abszk=(4.6) dispart=(0(10)50)) post vsquish level(90)

logit memberleft c.abszk##c.dispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
eststo pp4: margins, at(appropcomm=(1) abszk=(4.6) dispart=(0(10)50)) post vsquish level(90)

*margins are here:
use "marginaleffects_departlogit_outlier_appropcomm_113019_v1.dta", clear

graph twoway (connected margin dispartvary if kernelldispred=="min" & appropcomm==0, sort lcolor(black) lpattern(solid) lwidth(thin) msymbol(none) yaxis(1)) ///
(connected lci dispartvary if kernelldispred=="min" & appropcomm==0 , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected uci dispartvary if kernelldispred=="min" & appropcomm==0, sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected margin dispartvary if kernelldispred=="min" & appropcomm==1, sort lcolor(black) lpattern(solid) lwidth(thick) msymbol(none) yaxis(1)) ///
(connected lci dispartvary if kernelldispred=="min"  & appropcomm==1, sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected uci dispartvary if kernelldispred=="min" && appropcomm==1 , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)), ///
ytitle("Predicted Pr(Committee Departure)", axis(1)) xtitle("Presidential Vote District Partisanship") ///
 ylabel(0(.1)1, axis (1) valuelabel) ///
xlabel(0(10)50, valuelabel) legend(col(1) order(1 "Pred. Prob. for Non-Distributive Comms." 4 "Pred. Prob. for Distributive Comms." 3 "95% Confidence Interval" ) ///
bplacement(nw) ring(1) size(small)) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) title("Minimum Member" "Outlierness")
graph save conditionalleavecomms_min.gph, replace


graph twoway (connected margin dispartvary if kernelldispred=="max" & appropcomm==0, sort lcolor(gray) lpattern(solid) lwidth(thin) msymbol(none) yaxis(1)) ///
(connected lci dispartvary if kernelldispred=="max" & appropcomm==0 , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected uci dispartvary if kernelldispred=="max" & appropcomm==0 , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected margin dispartvary if kernelldispred=="max" & appropcomm==1, sort lcolor(black) lpattern(solid) lwidth(thick) msymbol(none) yaxis(1)) ///
(connected lci dispartvary if kernelldispred=="max"  & appropcomm==1 , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected uci dispartvary if kernelldispred=="max" && appropcomm==1  , sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)), ///
ytitle("Predicted Pr(Committee Departure)", axis(1)) xtitle("Presidential Vote District Partisanship") ///
ylabel(0(.1)1, axis (1) valuelabel)  ///
xlabel(0(10)50, valuelabel) legend(col(1) order(1 "Pred. Prob. for Non-Distributive Comms." 4 "Pred. Prob. for Distributive Comms." 3 "95% Confidence Interval" ) ///
bplacement(nw) ring(1) size(small)) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) title("Maximum Member" "Outlierness")
graph save conditionalleavecomms_max.gph, replace

graph combine conditionalleavecomms_min.gph conditionalleavecomms_max.gph, scheme(s1mono) graphregion(fcolor(white) ifcolor(white))




************************************
*As requested by reviewer, drop Intelligence Committee, check robustness


use "clogit_final_v3_030720.dta", clear

drop if stewartcommid==242


*scale partydiff
replace partydiff=partydiff/100
replace lagpartydiff=lagpartydiff/100

replace partydiff_wo=partydiff_wo/100
replace lagpartydiff_wo=lagpartydiff_wo/100



*Table: Fixed Effects Logit Estimates of Committee Assignment

*with kernell district ideology
*for reference to compare to fixed effects logit
clogit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.cong, group(icpsr)
*number of distinct obs used in analysis
egen icpsr_comm_cong = concat(icpsr stewartcommid cong) if commassignid==1
qui tab icpsr_comm_cong if e(sample)
di r(r)

*with pres. district partisanship
clogit commassignid c.dispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong, group(icpsr)
qui tab icpsr_comm_cong if e(sample)
di r(r)


*both district partisanship measures--actual models in the papers
eststo c1: logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong, cluster(stewartcommid)
*egen icpsr_comm_cong = concat(icpsr stewartcommid cong) if commassignid==1
qui tab icpsr_comm_cong if e(sample)
di r(r)


eststo c2: logit commassignid c.lndispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong, cluster(stewartcommid)
qui tab icpsr_comm_cong if e(sample)
di r(r)

estout c1 c2, style(tex) cells(b(star fmt(2)) se(par)) starlevels($^\#$ .1 * 0.05) stats(aic N r2) varlabels( ///
lnkernelldispart	"Logged Kernell District Ideology" lagpartydiff_wo "Lagged Avg. Diff. in Committee Partisan Voting"  lndispart "Logged Presidential Vote District Ideology"  ///
rankwithinparty "Committee Party Seniority Rank" commseniority "Committee Overall Seniority" ///
permaj "Maj. Party Percent of Committee Seats")



*Figure: Predicted Probabilities of Committee Choice Conditional on Kernell District Ideology and Average Difference in Partisan Voting

*marginal effects, pred probs
logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong, cluster (stewartcommid)
eststo cp1: margins, at(lnkernelldispart=(-6.907755) lagpartydiff_wo=(0(.25)1)) post vsquish 


logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong, cluster(stewartcommid)
eststo cp2: margins, at(lnkernelldispart=(1.233143) lagpartydiff_wo=(0(.25)1)) post vsquish 







*Table: The Conditional Effect of Distributive Committees on District Partisanship and Partisan Committee Membership
use "clogit_final_v3_030720.dta", clear

drop if stewartcommid==242


*scale partydiff
replace partydiff=partydiff/100
replace lagpartydiff=lagpartydiff/100

replace partydiff_wo=partydiff_wo/100
replace lagpartydiff_wo=lagpartydiff_wo/100


gen appropcomm=0
replace appropcomm=1 if fkconstit==1 
replace appropcomm=1 if stewartcommid==104


eststo dist_m1: logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong if appropcomm==0, cluster(stewartcommid)
eststo dist1: margins, at(lnkernelldispart=(-6.907755) lagpartydiff_wo=(0(.25)1)) post vsquish 
egen icpsr_comm_cong = concat(icpsr stewartcommid cong) if commassignid==1
qui tab icpsr_comm_cong if e(sample)
di r(r)

eststo dist_m2: logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong if appropcomm==1, cluster(stewartcommid)
eststo dist2: margins, at(lnkernelldispart=(-6.907755) lagpartydiff_wo=(0(.25)1)) post vsquish 
qui tab icpsr_comm_cong if e(sample)
di r(r)

eststo dist_m3: logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong if appropcomm==0, cluster(stewartcommid)
eststo dist3: margins, at(lnkernelldispart=(1.233143) lagpartydiff_wo=(0(.25)1)) post vsquish 

eststo dist_m4: logit commassignid c.lnkernelldispart##c.lagpartydiff_wo rankwithinparty commseniority permaj i.stewartcommid i.cong if appropcomm==1, cluster(stewartcommid)
eststo dist4: margins, at(lnkernelldispart=(1.233143) lagpartydiff_wo=(0(.25)1)) post vsquish 

estout dist_m1 dist_m2, style(tex) cells(b(star fmt(2)) se(par)) starlevels($^\#$ .1 * 0.05) stats(aic N r2) varlabels( ///
lnkernelldispart	"Logged Kernell District Ideology" lagpartydiff_wo "Lagged Avg. Diff. in Committee Partisan Voting"  lndispart "Logged Presidential Vote District Ideology"  ///
rankwithinparty "Committee Party Seniority Rank" commseniority "Committee Overall Seniority" ///
permaj "Maj. Party Percent of Committee Seats")





*Table: The Conditional Effect of Outlying District Preferences on Committee Departure
*Drop Intelligence committee
use "datwcommpart_v5_030720.dta", clear
drop if stewartcommid==242


eststo int1: logit memberleft c.abszk##c.votepct rankwithinparty female membermajparty memberparty commleader i.stewartcommid i.cong numterms, cluster(stewartcommid)
margins, at(abszk=(0) votepct=(40(10)100)) post vsquish

logit memberleft c.abszk##c.votepct rankwithinparty female membermajparty memberparty commleader i.stewartcommid i.cong numterms, cluster(stewartcommid)
margins, at(abszk=(4.6) votepct=(40(10)100)) post vsquish


eststo int2: logit memberleft c.abszk##c.kernelldispart rankwithinparty female membermajparty memberparty commleader i.stewartcommid i.cong numterms, cluster(stewartcommid)
margins, at(abszk=(0) kernelldispart=(0(1)3.4)) level(90)

logit memberleft c.abszk##c.kernelldispart rankwithinparty female membermajparty memberparty commleader i.stewartcommid i.cong numterms, cluster(stewartcommid)
margins, at(abszk=(2) kernelldispart=(0(1)3.4)) level(90)


eststo int3: logit memberleft c.abszk##c.dispart rankwithinparty female membermajparty memberparty commleader i.stewartcommid i.cong numterms, cluster(stewartcommid)
eststo pp1: margins, at(abszk=(0) dispart=(0(10)50)) post vsquish

logit memberleft c.abszk##c.dispart rankwithinparty female membermajparty memberparty commleader i.stewartcommid i.cong numterms, cluster(stewartcommid)
eststo pp2: margins, at(abszk=(4.6) dispart=(0(10)50)) post vsquish

estout int1 int2 int3, style(tex) cells(b(star fmt(2)) se(par)) starlevels($^\#$ .1 * 0.05) stats(aic N r2_p) varlabels( ///
abszk "Member Outlierness (Kernell)" votepct "Member Vote Percentage" kernelldispart "Kernell District Partisanship" dispart "Presidential Vote District Partisanship" ///
rankwithinparty "Committee Party Seniority Rank" female "Gender (Female=1)" membermajparty "Majority Party Member (Yes=1)" ///
memberparty "Member Party (Dem.=1)" commleader "Chair or Ranking Member of Any Committee" numterms "Number of Terms Served")




*Table: The Conditional Effect of Outlying District Preferences and Distributive Committee on Committee Departure

use "datwcommpart_v5_030720.dta", clear
drop if stewartcommid==242

gen appropcomm=0
replace appropcomm=1 if fkconstit==1 
replace appropcomm=1 if stewartcommid==104

eststo absapprop1: logit memberleft c.abszk##c.votepct##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj numterms i.cong numterms, cluster(stewartcommid)
margins, at(abszk=(0) votepct=(40(10)100)) post vsquish

logit memberleft c.abszk##c.votepct##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
margins, at(abszk=(4.6) votepct=(40(10)100)) post vsquish


eststo absapprop2: logit memberleft c.abszk##c.kernelldispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
margins, at(appropcomm=(0) abszk=(0) kernelldispart=(0(1)3.4)) level(90)

logit memberleft c.abszk##c.kernelldispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
margins, at(appropcomm=(1) abszk=(0) kernelldispart=(0(1)3.4)) level(90)


eststo absapprop3: logit memberleft c.abszk##c.dispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
eststo pp1: margins, at(abszk=(0) dispart=(0(10)50)) post vsquish

logit memberleft c.abszk##c.dispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
eststo pp2: margins, at(abszk=(4.6) dispart=(0(10)50)) post vsquish

estout absapprop1 absapprop2 absapprop3, style(tex) cells(b(star fmt(2)) se(par)) starlevels($^\#$ .1 * 0.05) stats(aic N r2_p) varlabels( ///
abszk "Member Outlierness (Kernell)" votepct "Member Vote Percentage" kernelldispart "Kernell District Partisanship" dispart "Presidential Vote District Partisanship" ///
rankwithinparty "Committee Party Seniority Rank" female "Gender (Female=1)" membermajparty "Majority Party Member (Yes=1)" ///
memberparty "Member Party (Dem.=1)" commleader "Chair or Ranking Member of Any Committee" numterms "Number of Terms Served" grosewart "Grosewart Committee Value" permaj "Maj. Party Percent of Committee Seats")

*Figure: Predicted Probabilities of Committee Departures Conditional on Outlying Preferences, Distributive Committee, and District Partisanship

eststo absapprop3: logit memberleft c.abszk##c.dispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
eststo pp1: margins, at(appropcomm=(0) abszk=(0) dispart=(0(10)50)) post vsquish level(90)

logit memberleft c.abszk##c.dispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
eststo pp2: margins, at(appropcomm=(1) abszk=(0) dispart=(0(10)50)) post vsquish level(90)

eststo absapprop3: logit memberleft c.abszk##c.dispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
eststo pp3: margins, at(appropcomm=(0) abszk=(4.6) dispart=(0(10)50)) post vsquish level(90)

logit memberleft c.abszk##c.dispart##i.appropcomm rankwithinparty female membermajparty memberparty commleader grosewart permaj i.cong numterms, cluster(stewartcommid)
eststo pp4: margins, at(appropcomm=(1) abszk=(4.6) dispart=(0(10)50)) post vsquish level(90)
